package com.kinglone.back.role.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.kinglone.back.role.model.Role;
import com.kinglone.back.role.service.RoleService;
import com.kinglone.back.user.model.User;
import com.kinglone.back.user.service.UserService;

@Controller
@RequestMapping("/back/role")
public class RoleController {

	@Autowired
	private RoleService roleService;
	@Autowired
	private UserService userService;
	
	/**
	 * 跳转到角色列表
	 * @param request
	 * @return
	 */
	@RequestMapping("/role-list.htm")
	public ModelAndView roleList(HttpServletRequest request){
		ModelAndView mv = new ModelAndView("back/role/role-list");
		List<Role> roleList = roleService.getAllRoles();
		mv.addObject("roleList", roleList);
		return mv;
	}
	/**
	 * 跳转到角色已绑定用户页面
	 * @param roleId
	 * @return
	 */
	@RequestMapping("/role-add-user.htm")
	public ModelAndView roleAddUser(@RequestParam(value="roleId")String roleId){
		ModelAndView mv = new ModelAndView("back/role/role-add-user");
		List<User> userList = userService.getUsersByRoleId(roleId);
		mv.addObject("userList", userList);
		mv.addObject("roleId", roleId);
		return mv;
	}
	

}
